﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// MessageView.xaml 的交互逻辑
    /// </summary>
    public partial class MessageView : Window
    {
        public MessageView(string message , int a)
        {
            InitializeComponent();
            CancelBtn.Visibility = Visibility.Collapsed;
            MessageText.Text = message;

            if (a == 1)
            {
                CancelBtn.Visibility = Visibility.Visible;
            }
            else
            {
                CancelBtn.Visibility = Visibility.Collapsed;
            }

        }

        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }


        public static MessageBoxResult Show(string message, string caption, MessageBoxButton buttons)
        {
            MessageView messageView;

            // 根据 buttons 参数来设置 Cancel 按钮的可见性
            if (buttons == MessageBoxButton.OKCancel)
            {
                messageView = new MessageView(message, 1);
            }
            else
            {
                messageView = new MessageView(message, 0);
            }

            messageView.Title = caption;

            messageView.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            // 显示对话框并获取结果
            bool? result = messageView.ShowDialog();

            if (result == true)
            {
                return MessageBoxResult.OK;
            }
            else
            {
                return MessageBoxResult.Cancel;
            }
        }



    }
}
